/*
 * SocketConnection.h
 *
 *  Created on: 2012-2-6
 *      Author: chenjialiang
 */

#pragma once

#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#include "../utils/Log.h"

namespace Zha
{

class SocketConnection
{
public:
	SocketConnection();
	virtual ~SocketConnection();

public:
	int Init();
	int Read(int clientSocket, char* buf, int size);

	//returns socket fd or -1
	int Accept();

public:
	bool GetReusePort() { return m_reusePort; }
	bool GetBlock() { return m_block; }
	int GetPort() { return m_bindPort; }
	std::string GetAddr() { return m_bindAddr; }
	int GetSocketFD() { return m_socket; }

public:
	void SetReusePort(bool b) { m_reusePort = b;}
	void SetBlock(bool b) { m_block = b;}
	void SetPort(int port) { m_bindPort = port;}
	void SetAddr(std::string& addr) { m_bindAddr = addr;}

protected:
	bool m_reusePort;
	bool m_block;
	std::string m_bindAddr;
	int m_bindPort;
	int m_socket;
};

}
